840481d0a72bafd712440024e4792ec396bf3c9a,platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java,CodeCompletionHandlerBase,invokeCompletion,#Project#Editor#PsiFile#number#,109

Before Change


      CommandProcessor.getInstance().executeCommand(project, initCmd, null, null);
    }

    final int offset1 = initializationContext[0].getStartOffset();
    final int offset2 = initializationContext[0].getSelectionEndOffset();
    final OffsetMap offsetMap = initializationContext[0].getOffsetMap();
    final CompletionContext context = new CompletionContext(project, editor, psiFile, offsetMap);

    doComplete(offset1, offset2, context, initializationContext[0].getFileCopyPatcher(), editor, time, offsetMap);
  }

  private boolean shouldFocusLookup(CompletionParameters parameters) {

After Change


    }
  }

  public void invokeCompletion(final Project project, final Editor editor, final PsiFile psiFile, int time) {
    if (!ApplicationManager.getApplication().isUnitTestMode()) {
      assert !ApplicationManager.getApplication().isWriteAccessAllowed() : "Completion should not be invoked inside write action";
    }

    final Document document = editor.getDocument();
    if (!FileDocumentManager.getInstance().requestWriting(document, project)) {
      return;
    }

    psiFile.putUserData(PsiFileEx.BATCH_REFERENCE_PROCESSING, Boolean.TRUE);

    final CompletionProgressIndicator indicator = CompletionServiceImpl.getCompletionService().getCurrentCompletion();
    if (indicator != null) {
      if (indicator.isRepeatedInvocation(myCompletionType, editor)) {
        if (!indicator.isRunning() && (!isAutocompleteCommonPrefixOnInvocation() || indicator.fillInCommonPrefix(true))) {
          return;
        }
        else {
          time = indicator.getParameters().getInvocationCount() + 1;
          new WriteCommandAction(project) {
            protected void run(Result result) throws Throwable {
              indicator.restorePrefix();
            }
          }.execute();
        }
      }
      indicator.closeAndFinish(false);
    }

    if (time > 1) {
      if (myCompletionType == CompletionType.CLASS_NAME) {
        FeatureUsageTracker.getInstance().triggerFeatureUsed(CodeCompletionFeatures.SECOND_CLASS_NAME_COMPLETION);
      }
      else if (myCompletionType == CompletionType.BASIC) {
        FeatureUsageTracker.getInstance().triggerFeatureUsed(CodeCompletionFeatures.SECOND_BASIC_COMPLETION);
      }
    }

    final CompletionInitializationContext[] initializationContext = {null};


    Runnable initCmd = new Runnable() {
      @Override
      public void run() {

        Runnable runnable = new Runnable() {
          public void run() {
            final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);

            EditorUtil.fillVirtualSpaceUntilCaret(editor);
            documentManager.commitAllDocuments();

            final Ref<CompletionContributor> current = Ref.create(null);
            initializationContext[0] = new CompletionInitializationContext(editor, psiFile, myCompletionType) {
              CompletionContributor dummyIdentifierChanger;
              @Override
              public void setFileCopyPatcher(@NotNull FileCopyPatcher fileCopyPatcher) {
                super.setFileCopyPatcher(fileCopyPatcher);

                if (dummyIdentifierChanger != null) {
                  LOG.error("Changing the dummy identifier twice, already changed by " + dummyIdentifierChanger);
                }
                dummyIdentifierChanger = current.get();
              }
            };
            for (final CompletionContributor contributor : CompletionContributor.forLanguage(PsiUtilBase.getLanguageInEditor(editor, project))) {
              if (DumbService.getInstance(project).isDumb() && !DumbService.isDumbAware(contributor)) {
                continue;
              }

              current.set(contributor);
              contributor.beforeCompletion(initializationContext[0]);
              assert !documentManager.isUncommited(document) : "Contributor " + contributor + " left the document uncommitted";
            }
          }
        };
        ApplicationManager.getApplication().runWriteAction(runnable);
      }
    };
    if (autopopup) {
      CommandProcessor.getInstance().runUndoTransparentAction(initCmd);
    } else {
      CommandProcessor.getInstance().executeCommand(project, initCmd, null, null);
    }

    doComplete(time, initializationContext[0]);
  }

  private boolean shouldFocusLookup(CompletionParameters parameters) {